/*
 * @Author: 明月下
 * @Date: 2022-07-30 18:47:56
 * @LastEditors: 明月下
 * @LastEditTime: 2022-08-01 00:48:50
 * @FilePath: \ali-yun-slimming\express\routes\slimming.js
 * @Description: slimming的路由 前缀要加/slimming
 */

const express = require('express')
let route = express.Router()

const slimmingModule = require('../modules/slimming')

route.post('/init',async (req,res) => {
    try {
        await slimmingModule.init(req.body)
        res.status(201).send()
    } catch (error) {
        console.error(error)
        res.status(500).send()
    }
})

route.post('/get',async (req,res) => {
    try {
        const result = await slimmingModule.getByName(req.body?.name)
        res.status(201).send(result)
    } catch (error) {
        console.error(error)
        res.status(500).send()
    }
})

route.post('/add',async (req,res) => {
    try {
        const result = await slimmingModule.addWeight(req.body.name, req.body.weight, req.body.date)
        res.status(201).send(result)
    } catch (error) {
        console.error(error)
        res.status(500).send()
    }
})

module.exports = route